package edu.gyc.objecthomework;

public class Movie
{
	private String name;
	private String ratingMPAA;

	private int numRated1 = 0, numRated2 = 0, numRated3 = 0, numRated4 = 0, numRated5 = 0;

	public void setName(String newName)
	{
		name = newName;
	}
	public String getName()
	{
		return name;
	}
	public void setRating(String newRating)
	{
		ratingMPAA = newRating;
	}
	public String getRating()
	{
		return ratingMPAA;
	}

	public void addRating(int num)
	{
		if ((num < 1) || (num > 5))
			return;

		switch (num)
		{
			case 1:
				numRated1++;
				break;
			case 2:
				numRated2++;
				break;
			case 3:
				numRated3++;
				break;
			case 4:
				numRated4++;
				break;
			case 5:
				numRated5++;
				break;
		}
	}

	public double getAverage()
	{
		return (numRated1 + 2*numRated2 + 3*numRated3 + 4*numRated4 + 5*numRated5) / 5.0;
	}

	public static void main(String[] args)
	{
		Movie m1 = new Movie();
		m1.setName("The Adjustment Bureau");
		m1.setRating("PG-13");
		m1.addRating(5);
		m1.addRating(5);
		m1.addRating(4);
		m1.addRating(4);
		m1.addRating(5);
		System.out.println(m1.getName() + "," + m1.getRating() +
			" Average rating: " + m1.getAverage());

		Movie m2 = new Movie();
		m2.setName("I Am Number Four");
		m2.setRating("PG-13");
		m2.addRating(3);
		m2.addRating(2);
		m2.addRating(2);
		m2.addRating(4);
		m2.addRating(1);
		System.out.println(m2.getName() + "," + m2.getRating() +
			" Average rating: " + m2.getAverage());
	}
}
